package com.easwift.qsp.das.xgy;
import com.easwift.qsp.das.Test;
import com.easwift.qsp.das.xgy.BooleanHolder;
import jdk.nashorn.internal.runtime.linker.Bootstrap;

import java.io.BufferedOutputStream;

/**
 * 写数据线程
 *
 * @author Administrator
 *
 */
public class XGSocketWriteThread extends Thread {

	private BufferedOutputStream bos;
	private long socketThreadId;

	public XGSocketWriteThread(BufferedOutputStream bos, long socketThreadId) {
		super();
		this.bos = bos;
		this.socketThreadId = socketThreadId;
	}

	@Override
	public void run() {
		// 线程结束标志
		BooleanHolder flag = new BooleanHolder();
		try {
			while (flag.getFlag()) {
				byte[] otherBytes = { (byte) 0xd7, (byte) 0xef, 0x02, 0x00, 0x00, 0x11, 0x00, 0x00, (byte) 0x08,
						0x00, (byte) 0xf8, (byte) 0xd3 };
				bos.write(otherBytes);
				bos.flush();
				Thread.sleep(3000);
			}
		} catch (Exception e) {
			// 如果是socket异常则结束内层线程和外层线程
			flag.setFlag(false);
			// 结束socket对应的读线程
			Test.socketThreadSet.remove(socketThreadId);
		}
	}

}
